package com.nts.bupna.util;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;

public final class StringUtil {

    private StringUtil() {/*prevent construction*/}

    public static boolean empty(final String s) {
        return s == null || s.isEmpty();
    }

    public static String stripQuotes(final String quoted) {
        if (empty(quoted) || !quoted.startsWith("\"") || ! quoted.endsWith("\"")) {
            throw new IllegalArgumentException("Bad argument: " + quoted);
        }
        return quoted.substring(1, quoted.length() - 1);
    }

    public static String concat(final Collection<String> strings) {
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw);
        for (final String string : strings) {
            pw.println(string);
        }
        return sw.toString();
    }

    public static String cap(final String string) {
        return string.substring(0, 1).toUpperCase() + string.substring(1);
    }

    public static String unescape(final String condition) {
        return condition.replaceAll("\\\\", "");
    }
}
